﻿using System;
using System.Collections.Generic;
using System.Text;

namespace StringFormats
{
    public class Library
    {
        public string BookName { get; }//书名
        public string Publishing { get; }//出版社
        public double Price { get; }//价格
        public string Author { get; }//作者
        public string Publication { get; } =  //出版号
        public Library(string bookname, string publishing, double price, string author, string publication)
        {
            BookName = bookname;
            Publishing = publishing;
            Price = price;
            Author = author;
            Publication = publication;
        }

        public override string ToString() => BookName + "  " + Author;

        public virtual string ToString(string format) => ToString(format, null);

        public string ToString(string format, IFormatProvider formatProvider)
        {
            switch (format)
            {
                case null:
                case "A":
                    return $"书名：{BookName}   出版社：{Publishing}   价格：{Price}   作者：{Author}   出版号{Publication}";
                case "N":
                    return ToString();
                case "P":
                    return BookName + " " + Price;
                default:
                    throw new FormatException($"invalid format string {format}");//错误提示
            }
        }

    }
}
